package com.wangqinlei.cowims126.service.impl;

import com.wangqinlei.cowims126.mapper.CategoryMapper;
import com.wangqinlei.cowims126.pojo.Category;
import com.wangqinlei.cowims126.service.CategoryService;
import com.wangqinlei.cowims126.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Classname CategoryServiceImpl
 * @Description None
 * @Date 2019/6/26 10:14
 * @Created by WDD
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public PageBean<Category> queryPage(Map<String, Object> paramMap) {
        PageBean<Category> pageBean = new PageBean<>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = pageBean.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Category> datas = categoryMapper.queryList(paramMap);
        pageBean.setDatas(datas);

        Integer totalsize = categoryMapper.queryCount(paramMap);
        pageBean.setTotalsize(totalsize);
        return pageBean;
    }

    @Override
    public int addCategory(Category category) {
        return categoryMapper.addCategory(category);
    }

    @Override
    @Transactional
    public int deleteCategory(List<Integer> ids) {
        return categoryMapper.deleteCategory(ids);
    }

    @Override
    public int editCategory(Category category) {
        return categoryMapper.editCategory(category);
    }

    @Override
    public Category findByName(String categoryName) {
        return categoryMapper.findByName(categoryName);
    }

}
